﻿Imports XL.Common
Imports XL.Common.Utils
Imports XL.Win
Imports XL.Win.Utils
Imports Microsoft.Office.Interop.Excel

Namespace Utils


    Public Class TK

        Public Shared Function GetUserOptionsBox() As XL.Win.Component.OptionsBox


            Return New UserOptionsBox

        End Function

        Public Shared Function GetSecureOptionsBox() As XL.Win.Component.OptionsBox

            Return New SecureOptionsBox

        End Function

        Public Shared Sub InitDefaultData()

            Try

                Dim serviceTK = RExpXService.ServiceTK.GetInstance()
                serviceTK.ServMakeupNullFields()
                serviceTK.ServInitDefaultCommonItem( _
                    RExpXService.Decls.DEFAULT_CI_VALUE_IDENTITY_CARD_TYPE_RESIDENT, _
                    RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_NONE, _
                    RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_INFORM_STAFF_DELIVER, _
                    RExpXService.Decls.DEFAULT_CI_VALUE_INCOMING_CALL_TRANSACT_WAY_IGNORE _
                    )

                serviceTK.RegularSystemValues()


            Catch ex As Exception

                XL.Win.Window.XLMessageBox.ShowMessage( _
                    ex.Message, _
                    XL.Win.Window.XLMessageBox.MessageType.Wrong, _
                    MessageBoxButtons.OK)

            End Try


        End Sub

        Public Shared Sub ReloadCacheIncomingCallList()

            Dim dataFilePath = WinTK.GetResourceFilePath( _
                ResourceType.Docuemnt, _
                RExpXService.Decls.FILENAME_CACHE_INCOMING_POST_BOOKING_CALL_LIST)

            If IO.File.Exists(dataFilePath) = False Then
                Return
            End If
            Utils.Decls.CACHE_INCOMING_CALL_LIST.SetXml(IO.File.ReadAllText(dataFilePath))



        End Sub

        Public Shared Sub OverwriteCacheIncomingCallList()

            Dim dataFilePath = WinTK.GetResourceFilePath( _
                ResourceType.Docuemnt, _
                RExpXService.Decls.FILENAME_CACHE_INCOMING_POST_BOOKING_CALL_LIST)

            Utils.Decls.CACHE_INCOMING_CALL_LIST.SaveXml(dataFilePath)

        End Sub

        Public Shared Sub MoveCacheIncomingCallListToDB()

            Dim serviceTK = RExpXService.ServiceTK.GetInstance

            serviceTK.ServMigrateCacheCallListToDB(Utils.Decls.CACHE_INCOMING_CALL_LIST)

        End Sub

        Public Shared Sub DownloadOffLineData()

            'RExpXAuto.Facade.AfBizMaster.SwitchDataReadStyles(XL.DB.DBDecl.DataReadStyle.Local)
            'RExpXAuto.Facade.AfCIV.SwitchDataReadStyles(XL.DB.DBDecl.DataReadStyle.Local)      
            'RExpXAuto.Facade.AfSysConfig.SwitchDataReadStyles(XL.DB.DBDecl.DataReadStyle.Local)
            'RExpXAuto.Facade.AfMV.ReadMV_USERDataStyle = XL.DB.DBDecl.DataReadStyle.Local      

            'RExpXAuto.DataCache.DCHBizMaster.OverwriteCacheFromDB()                            
            'RExpXAuto.DataCache.DCHCIV.OverwriteCacheFromDB()                                  
            'RExpXAuto.DataCache.DCHSysConfig.OverwriteCacheFromDB()                            
            'RExpXAuto.DataCache.DCHMV.OverwriteMV_USERFromDB(, False)                          

        End Sub


        Public Shared Sub ExportSLog(ByVal fileName As String, ByVal fromDate As DateTime, ByVal toDate As DateTime)

            Dim SLogConditions As New RExpXAuto.Facade.AfSysConfig.ConditionOfS_LOG(XL.DB.Utils.Condition.LogicOperators.Logic_And)
            SLogConditions.Add( _
                RExpXAuto.Facade.AfSysConfig.S_LOGColumns.CREATE_TIMEColumn, _
                ">=", _
                CommTK.GetBeginOfDate(fromDate))

            SLogConditions.Add( _
                RExpXAuto.Facade.AfSysConfig.S_LOGColumns.CREATE_TIMEColumn, _
                "<=", _
                CommTK.GetBeginOfDate(toDate))

            Dim SLogList As New RExpXAuto.FTs.FT_S_LOG
            RExpXAuto.Facade.AfSysConfig.FillFT_S_LOG(SLogConditions, SLogList)

            If SLogList.Count = 0 Then
                Dim ex As New XLException(XLException.ErrorClassify.ReadDataError)
                ex.SetMessage(RExpXService.Decls.MSG_ALERT_00022)
                Throw ex
            End If

            If IO.File.Exists(fileName) = True Then
                IO.File.Delete(fileName)
            End If

            Dim toExcel As New Utils.ExcelTK(fileName)

            Dim cellFont As System.Drawing.Font

            toExcel.MergeCell(1, 1, 1, 4)
            toExcel.SetRowHeight(1, 35.25)

            toExcel.SetColumnWidth(1, 10)
            toExcel.SetColumnWidth(2, 15)
            toExcel.SetColumnWidth(3, 15)
            toExcel.SetColumnWidth(4, 10)

            cellFont = New System.Drawing.Font("Arial", 16, FontStyle.Bold)
            toExcel.SetCellText(1, 1, CommTK.GetTranslatedString("日志管理"), cellFont, Color.Black, Color.White)

            toExcel.MergeCell(3, 1, 3, 4)
            cellFont = New System.Drawing.Font("Arial", 10, FontStyle.Bold)
            toExcel.SetCellText(3, 1, CommTK.GetTranslatedString("日期从:") + String.Format("   {0:yyyy-MM-dd}   ", fromDate) + CommTK.GetTranslatedString("至:") + String.Format("   {0:yyyy-MM-dd}", toDate), cellFont, Color.Black, Color.White)

            toExcel.SetCellText(6, 1, CommTK.GetTranslatedString("序号"), cellFont, Color.Black, Color.White)
            toExcel.SetCellText(6, 2, CommTK.GetTranslatedString("创建时间"), cellFont, Color.Black, Color.White)
            toExcel.SetCellText(6, 3, CommTK.GetTranslatedString("创建帐号"), cellFont, Color.Black, Color.White)
            toExcel.SetCellText(6, 4, CommTK.GetTranslatedString("日志内容"), cellFont, Color.Black, Color.White)

            Dim rowCounter As Integer = 7
            Dim counter As Integer = 1

            cellFont = New System.Drawing.Font("Arial", 10, FontStyle.Regular)

            XL.Win.Window.XLProgressBox.SetProgressRange(SLogList.Count + rowCounter, 400, False)

            For Each SLogRow As RExpXAuto.FTs.FT_S_LOGRow In SLogList

                toExcel.SetCellText(rowCounter, 1, CommTK.FString(counter), cellFont, Color.Black, Color.White)
                toExcel.SetCellText(rowCounter, 2, String.Format("{0:yyyy-MM-dd}", SLogRow.CREATE_TIME), cellFont, Color.Black, Color.White, )
                toExcel.SetCellText(rowCounter, 3, SLogRow.CREATE_ACCOUNT, cellFont, Color.Black, Color.White)
                toExcel.SetCellText(rowCounter, 4, SLogRow.CONTENT, cellFont, Color.Black, Color.White)

                rowCounter += 1
                counter += 1

                XL.Win.Window.XLProgressBox.DisplayProgress(RExpXService.Decls.MSG_PROGRESS_0001, rowCounter, SLogRow.CREATE_TIME.ToString("yyyy-MM-dd HH:mm"))

            Next

            XL.Win.Window.XLProgressBox.CloseXLProgressBox()

            toExcel.SetFrameLine(6, 1, rowCounter - 1, 4, ExcelTK.BorderPart.Bottom Or ExcelTK.BorderPart.Horizonal, Color.Black, , XlBorderWeight.xlHairline)
            toExcel.SetFrameLine(5, 1, rowCounter - 1, 4, ExcelTK.BorderPart.Top Or ExcelTK.BorderPart.Bottom, Color.Black, , XlBorderWeight.xlThick)

            cellFont = New System.Drawing.Font("Arial", 10, FontStyle.Bold)

            'Dim staffRow As RExpXAuto.FTs.FT_M_STAFFRow = XAuto.Facade.AfBasicMaster.GetM_STAFFRow(Utils.Decls.LOGIN_STAFF_ID)                                                                                                                                                                                           
            '                                                                                                                                                                                                                                                                                                         
            'If IsNothing(staffRow) = False Then                                                                                                                                                                                                                                                                      
            '    toExcel.SetCellText(rowCounter + 2, 4, staffRow.STAFF_NAME, Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignRight, cellFont, Color.Black, Color.White)                                                                                                                                               
            'End If                                                                                                                                                                                                                                                                                                   

            If CommTK.FInteger(SysInfo.ReadLocalSysInfo(CommDecl.XLSSVN_SYSTEM_LANGUAGE)) = 1 Then
                toExcel.SetCellText(rowCounter + 3, 4, CommTK.FString(CommTK.GetSyncServerTime), cellFont, Color.Black, Color.White, "[$-409]yyyy-mmm-dd;@")
            Else
                toExcel.SetCellText(rowCounter + 3, 4, String.Format("{0:yyyy-MM-dd}", CommTK.GetSyncServerTime), cellFont, Color.Black, Color.White)
            End If

            toExcel.SaveAndClose()


        End Sub

        Public Shared Sub RefreshICServiceStatus()

        End Sub

    End Class

End Namespace

